package com.nayun.gjh.xiaokabanghou.common;

import com.nayun.gjh.xiaokabanghou.model.User;
import com.nayun.gjh.xiaokabanghou.model.request.SafetyUserRequest;
import com.nayun.gjh.xiaokabanghou.model.response.SafetyUserResponse;
import lombok.Data;

import javax.servlet.http.HttpServletRequest;

import static com.nayun.gjh.xiaokabanghou.constant.UserConstant.USER_LOGIN_KEY;
import static com.nayun.gjh.xiaokabanghou.constant.UserConstant.USER_SAFETY_KEY;

@Data
public class HttpSessionUtil {
    private HttpServletRequest httpServletRequest;

    public static SafetyUserRequest getLoginUser(HttpServletRequest httpServletRequest) {
        Object attribute = httpServletRequest.getSession().getAttribute(USER_LOGIN_KEY);
        if (attribute == null) {
            return null;
        }
        return (SafetyUserRequest) attribute;
    }

    public static SafetyUserRequest getSafetyUser(HttpServletRequest httpServletRequest) {
        Object attribute = httpServletRequest.getSession().getAttribute(USER_SAFETY_KEY);
        if (attribute == null) {
            return null;
        }
        return (SafetyUserRequest) attribute;
    }
}